package com.isoft.demo.service.impl;

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.MaintenanceDao;
import com.isoft.demo.entity.Maintenance;
import com.isoft.demo.entity.Vehicle;
import com.isoft.demo.service.MaintenanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class MintenanceServiceImpl implements MaintenanceService {
    @Resource
    private MaintenanceDao maintenanceDao;

    @Override
    public ResponseData addMain(Maintenance maintenance) {
        int n = maintenanceDao.addMain(maintenance);
        ResponseData rs = new ResponseData();
        List list = new ArrayList();
        if(n > 0){
            rs.setCode(0);
            rs.setMsg("添加成功");
            list.add(maintenance);
            rs.setData(list);
        } else{
            rs.setCode(1);
            rs.setMsg("添加失败");
        }
        return rs;
    }

    @Override
    public ResponseData updateMain(Maintenance maintenance) {
        int m = maintenanceDao.updateMain(maintenance);
        ResponseData rs = new ResponseData();
        if(m != 0){
            rs.setCode(0);
            rs.setMsg("修改成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("修改失败!");
        }
        return rs;
    }

    @Override
    public ResponseData findAllMain() {
        List<Maintenance> list = maintenanceDao.findAllMain();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }


    @Override
    public ResponseData findByMid(Integer mid) {
        List<Maintenance>list = maintenanceDao.findByMid(mid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }
}
